<?php

namespace app\api\controller;

use app\common\controller\Api;
use app\common\model\Category;
use app\common\model\Download as ModelDownload;

/**
 * 下载中心接口
 */
class Download extends Api
{
    protected $noNeedLogin = ['*'];
    protected $noNeedRight = ['*'];
    /**
     * @Author LK
     * @ApiTitle (下载中心分类)
     * @ApiMethod (GET)
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function category()
    {
        $lists = Category::all(['type' => 'downloadCategory', 'pid' => 0], ['child']);
        $this->success('请求成功', $lists);
    }

    /**
     * @Author LK
     * @ApiTitle (下载中心列表)
     * @ApiMethod (GET)
     * @ApiParams (name="first_cate", type="integer", required=true, sample="", description="一级分类")
     * @ApiParams (name="two_cate", type="integer", required=true, sample="", description="二级分类")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function lists()
    {
        $params = request()->param();
        extract($params);
        $download = $model = new ModelDownload();
        if (!isset($first_cate) || !$first_cate) {
            $this->error('参数错误');
        }
        $where['first_cate'] = $first_cate;

        if (isset($two_cate) && $two_cate) {
            $where['two_cate'] = $two_cate;

        }
        $images = ModelDownload::where('state', '1')->where($where)->order('id desc')->select();
        $video =  ModelDownload::where('state', '2')->where($where)->order('id desc')->select();
        $this->success('请求成功', compact('images', 'video'));
    }

    /**
     * @Author LK
     * @ApiTitle (下载中心详情)
     * @ApiMethod (GET)
     * @ApiParams (name="id", type="integer", required=true, sample="", description="ID")
     * @ApiReturnParams (name="code", type="integer", required=true, description="")
     * @ApiReturn ({'code':1,'msg':'返回成功'})
     */
    public function info()
    {
        $id = request()->param('id');
        $goods = ModelDownload::get($id);
        $this->success('请求成功', $goods);
    }
}
